package com.om.abom.ws;

import com.alibaba.fastjson2.JSON;
import org.springframework.web.socket.TextMessage;
import org.springframework.web.socket.WebSocketSession;

import java.io.IOException;

public class SocketSendMessageHelp
{
    private final WebSocketSession session;

    public record SocketSendMessage(String type, String msg)
    {
    }

    public SocketSendMessageHelp(WebSocketSession session)
    {
        this.session = session;
    }

    public void sendSuccessMsg(String msg) throws IOException
    {
        SocketSendMessage successMessage = new SocketSendMessage("successMessage", msg);
        session.sendMessage(new TextMessage(JSON.toJSONString(successMessage)));
    }

    public void sendErrorMsg(String msg) throws IOException
    {
        SocketSendMessage successMessage = new SocketSendMessage("errorMessage", msg);
        session.sendMessage(new TextMessage(JSON.toJSONString(successMessage)));
    }

    public void sendInfoMsg(String msg) throws IOException
    {
        SocketSendMessage successMessage = new SocketSendMessage("infoMessage", msg);
        session.sendMessage(new TextMessage(JSON.toJSONString(successMessage)));
    }
}
